<?php
/*
	Aurus CMS - free OOP CMS
	Copyright (C) 2010  Nestor Yanchuk

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
if (! defined('ROOT')) die();
class Captcha extends ParentCaptcha {
	var $img = null;
	var $code = '';
	function Captcha($code){
		$this->code = $code;
		$this->get_fonts();
		$this->draw();
		$this->out_img($this->wave($this->secondimage));
	}
	function draw(){
		$width = $this->width;
		$height = $this->height;

		$fontsize = mt_rand(22,27);
		$fontcorner = mt_rand(-5,5);

		$this->img = imagecreate($this->width,$this->height);
		if (mt_rand(1,2) == 1) {
			$this->textcolor  = imagecolorallocate($this->img ,mt_rand(1,100),mt_rand(1,100),mt_rand(1,100));
			$this->background = imagecolorallocate($this->img ,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
		} else {
			$this->textcolor = imagecolorallocate($this->img ,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
			$this->background = imagecolorallocate($this->img ,mt_rand(1,100),mt_rand(1,100),mt_rand(1,100));
		}

		$imagebox = imagettfbbox($fontsize,$fontcorner,$this->font,$this->code);

		$xpos = ceil(($height/2) - $imagebox[0]/2);

		imagettftext($this->img,$fontsize,$fontcorner,$xpos,40,$this->background,$this->font,$this->code);

		$this->secondimage = imagecreatetruecolor($this->width,$this->height);
		imagecopy($this->secondimage,$this->img,0,0,0,0,$this->width,$this->height);

		imagesetthickness($this->img,1);
		for ($i = 1;$i <= mt_rand(1,8);$i++) {
			imageline($this->img,mt_rand(0,($width-1)),mt_rand(0,($height-1)),mt_rand(0,($width-1)),mt_rand(0,($height-1)),$this->background);
		}
	}

}
